// src/utils/http.js
import axios from 'axios'
import { ElMessage } from 'element-plus'

const http = axios.create({
    baseURL: 'http://localhost:8088', // 关键修改点
    timeout: 10000
})

http.interceptors.response.use(
    response => response.data,
    error => {
        if (error.response?.status === 404) {
            ElMessage.error('接口不存在，请检查后端实现')
        }
        return Promise.reject(error)
    }
)

http.interceptors.response.use(response => {
    if (response.data?.blogs) {
        response.data.blogs = response.data.blogs.map(blog => ({
            ...blog,
            author: blog.author || { auid: 'null', username: '佚名' }
        }));
    }
    return response;
});


export default http